# 定义一个借记卡
# 属性 姓名 余额
# 方法 存钱 取钱 打印信息


# 定义一个信用卡 继承自借记卡
# 属性 信用额度（可透支多少)
# 用以下代码测试
# c1 = Card("张三", 1000)
# print(c1) # 打印输出 借记卡 张三 余额 1000
# c1.saveMoney(1000) # 打印输出 存入1000
# print(c1) # 打印输出 借记卡 张三 余额 1000
# c1.drawMoney(500) # 打印输出 取款500
# print(c1) # 打印输出 借记卡 张三 余额 1500
# c1.drawMoney(10000)# 打印输出 余额不足 交易失败
# print(c1) # 打印输出 借记卡 张三 余额 1500

# class DebitCard():
#     def __init__(self,name='XXX',balance=0):                # 定义属性 姓名 余额
#         self.type = '借记卡'
#         self.name = name
#         self.balance = balance
#
#     def savemoney(self,howmuchmoney=0):                     # 存钱行为，且返回‘余额’属性
#         if howmuchmoney > 0:
#             self.balance += howmuchmoney
#             print(f'存入{howmuchmoney}')
#         return int(self.balance)
#
#     def drawmoney(self,howmuchmoney=0):                      # 取钱行为，且返回‘余额’属性
#         if howmuchmoney > 0 and howmuchmoney <= self.balance:
#             self.balance -= howmuchmoney
#             print(f'取出{howmuchmoney}')
#         else:
#             print(f'取款金额{howmuchmoney}元，超出卡内余额，交易失败')
#         return int(self.balance)
#
# class Card(DebitCard):
#     def __str__(self):
#         return f'借记卡 {self.name} 余额 {self.balance}'
#
# c1 = Card('张三',1000)
# print(c1)
#
# c1.savemoney(1000)                      # 注意 ：执行玩一个行为后，该行为的结果会在下一次行为发生前暂时保留
# print(c1)
#
# c1.drawmoney(500)
# print(c1)
#
# c1.drawmoney(10000)
# print(c1)



# c2 = CreditCard("张三",5000,0)
# print(c2) # 打印输出 信用卡 张三 额度5000 余额 0
# c2.drawMoney(500) #  打印输出 刷卡500
# print(c2) # 打印输出 信用卡 张三 额度5000 余额 -500
# c2.saveMoney(500) # 打印输出 存入500
# print(c2) # 打印输出 信用卡 张三 额度5000 余额 0
# c2.drawMoney(50000) #  打印输出 额度不够 交易失败
# print(c2) # 打印输出 信用卡 张三 额度5000 余额 -500

class DebitCard():
    def __init__(self,name='XXX',quota=5000,svae_or_draw=0):                # 定义属性 姓名 余额 额度
        self.type = '信用卡'
        self.quota = quota
        self.name = name
        self.balance = svae_or_draw - 5000 + self.quota


    def savemoney(self,howmuchmoney=0):                     # 存钱行为，且返回‘余额’属性
        self.balance = self.quota + self.balance + howmuchmoney - 5000
        print(f'存了{howmuchmoney}元')
        return self.balance

    def drawmoney(self,howmuchmoney=0):
        if howmuchmoney <= self.quota + self.balance:
            self.balance = self.quota + self.balance - howmuchmoney - 5000
            print(f'刷卡{howmuchmoney}')
        else:
            self.balance = self.quota + self.balance  - 5000
            print('超出额度，交易失败')
        return self.balance


class CreditCard(DebitCard):
    def __str__(self):
        return f'{self.type} {self.name}  额度{self.quota} 余额{self.balance}'


c2 = CreditCard("张三",5000,0)
print(c2)
c2.savemoney(500)
print(c2)
c2.drawmoney(1000)
print(c2)
c2.drawmoney(1500)
print(c2)
c2.drawmoney(3500)
print(c2)
c2.savemoney(3000)
print(c2)
c2.drawmoney(4000)
print(c2)
